# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=winkerberos
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=0.7.0
pkgrel=1
pkgdesc="High level interface to SSPI for Kerberos client auth (mingw-w64)"
arch=('any')
url='https://github.com/mongodb-labs/winkerberos'
license=('Apache')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-sphinx"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
#checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pymongo")
options=('staticlibs' 'strip' '!debug')
_dtoken="85/b2/c5a66595bb477f1939596d80fa308e357c28abe22d3d6ce6cc2208c324ee"
source=("https://files.pythonhosted.org/packages/${_dtoken}/winkerberos-${pkgver}.zip"
       mingw-fixes.patch)
sha256sums=('e304c28de838a48206edfe58b8deb5209a3fd8c6a755bd521c1ee6e656b06e27'
            '2a3fe6e90b8ab3ead000e831878e089880d4402a7df7bca8e8615666b78b090d')

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  apply_patch_with_msg mingw-fixes.patch

  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

#check() {
#  cd "${srcdir}/${_realname}-${pkgver}"
#  ${MINGW_PREFIX}/bin/python setup.py test
#}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
